package com.b2.controller.wx;

import com.b2.pojo.dto.addTeacherDto;
import com.b2.pojo.entity.Teacher;
import com.b2.result.Result;
import com.b2.service.TeacherService;
import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/wx/teacher")
@Slf4j
@Api(tags = "微信老师相关接口")
@CrossOrigin
public class TeacherController {

    @Autowired
    TeacherService teacherService;
     //老师通过邀请码创建身份信息
    @PostMapping("addteacher")
    @ApiOperation(value = "老师通过邀请码创建身份信息")
    public Result addteacher(@RequestBody addTeacherDto teacher){
        teacherService.addteacher(teacher);
        return Result.success();
    }


    /**
     * 根据手机号查询老师姓名
     * @param phone
     * @return
     */
    @ApiOperation("根据手机号查询老师姓名")
    @PostMapping("/selectNameByPhone")
    public Result<String> selectName(String phone){
        if (phone == null){
            return Result.error("手机号不能为空");
        }
        Teacher teacher = teacherService.getOne(Wrappers.<Teacher>lambdaQuery().eq(Teacher::getPhone, phone));

        return Result.success(teacher.getName());
    }
}
